// const { createWriteStream, createReadStream } = require("fs");

const { createReadStream, createWriteStream } = require("fs");

// const writeStream = createWriteStream('./file.text', {
//     flags: 'a',
//     start:11
// })

// writeStream.write('我是天才');

// const readStream = createReadStream('./file.text');
// readStream.on('data', (data) => {
//     console.log(data.toString());
// })

//实现拷贝

const readStream = createReadStream('./file.text', {
    encoding:'utf-8'
});

const writeStream = createWriteStream('./copy_file.txt', {
    flags:'w+'
})

readStream.on('data', (data) => {
    writeStream.write(data);
})

//使用管道的方式进行传递数据
const writeStream2 = createWriteStream('./copy_file2.txt', {
    flags: 'w+'
})

readStream.pipe(writeStream2, { flags: 'w+' });

